{extend name="adminblue/base" /}
{block name="resources"/}
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_base.css">
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_index.css">
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_tooltip.css">
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_lib.css" />
<link rel="stylesheet" href="ADMIN_CSS/wxMenu/wx_richvideo.css" />
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style>
	.menu_setting_area{margin:30px;}
	.frm_control_group input{
		margin: 50px 0px 50px 50px;
	}
	.modal-backdrop, .modal-backdrop.fade.in {
		opacity: 0.1;
	}
</style>
<script src="ADMIN_JS/plugin/drag-arrange.js"></script>
<script src="ADMIN_JS/wx_menu/wx_menu.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
{/block}
{block name="main"}
<div class="frm_control_group js_setGraphic">
	<input type="radio" name="radio" value="1" onclick="test()">全部会员
	<input type="radio" name="radio" value="2" onclick="test()">部分会员
	<input type="radio" name="radio" value="3" onclick="test()" checked>指定会员
</div>
<!-- 	全部会员弹框  -->
<div class="modal fade hide" id="allUsers" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>消息发送</h3>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<textarea id="reply_all_content" placeholder="请输入消息内容......" style="width: 100%;height: 200px"></textarea>
				</div>
			</div>

			<div class="modal-footer">
				<button class="btn btn-primary" onclick="send_message()">发送</button>
				<button class="btn" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<!-- 	部分会员弹框  -->
<div class="modal fade hide" id="areaUsers" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">

		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>消息发送</h3>
			</div>
			<div class="modal-body" style="">
				<table class="table-class">
					<thead>
					<tr align="center">
						<th style="width: 20px;">  </th>
						<th style="text-align:left;">用户名</th>
					</tr>
					</thead>
					<tbody id="app">
					<tr align="center" v-for="(item,index) in items">
						<td style="width: 20px;text-align: center">
							<input type="checkbox" class="vue_index" name="uid" :value="item.uid">
						</td>
						<td align="left">
							<label style="float:none;width:100%">{{item.user_name}}</label>
						</td>
					</tr>
					</tbody>
				</table>
				<div class="page1" id="turn-ul" style="">
					<div class="pagination">
						<ul>
							<li class="total-data" data-total-count="">共0条数据</li>
							<li class="according-number">每页显示<input type="text" class="input-medium" id="showNumber" value="50" data-default="50" autocomplete="off">条</li>
							<li><a id="beginPage" class="page-disable" style="border: 1px solid #dddddd;">首页</a></li>
							<li><a id="prevPage" class="page-disable">上一页</a></li>
							<li id="pageNumber"></li>
							<li><a id="nextPage" class="page-disable">下一页</a></li>
							<li><a id="lastPage" class="page-disable">末页</a></li>
							<li class="page-count">共0页</li>
						</ul>
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<div class="modal-infp-style" style="margin-bottom: 25px">
					<textarea id="reply_area_content" placeholder="请输入消息内容......" style="width: 100%;height: 100px"></textarea>
				</div>
				<button class="btn btn-primary" onclick="send_area_message()">发送</button>
				<button class="btn" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<!-- 	指定会员弹框  -->
<div class="modal fade hide" id="oneUsers" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">

		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>消息发送</h3>
			</div>
			<div class="modal-body">
				<input type="text" id="user_name" placeholder="请输入会员名称" onblur="testUser(this.id,this.value)">
				<div class="modal-infp-style">
					<textarea id="reply_one_content" placeholder="请输入消息内容......" style="width: 100%;height: 200px"></textarea>
				</div>
			</div>

			<div class="modal-footer">
				<button class="btn btn-primary" onclick="send_onemessage()">发送</button>
				<button class="btn" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            items: [],
            uid:[]
        }
    });

    function test() {
        var id = $('input[name="radio"]:checked').val()?$('input[name="radio"]:checked').val():1;
        console.log(id);
        if(id==1){
            console.log("全部会员");
            $("#allUsers").modal("show");
        }else if (id==2) {
            console.log("'部分会员");
            LoadingInfo(1);
            $("#areaUsers").modal("show");
        }else{
            console.log("指定会员");
            $("#oneUsers").modal("show");
        }
    }
    //全部会员回复
    function send_message() {
        console.log("aaaa");
        // 拿到回复内容
        var reply_content = $("#reply_all_content").val();
        console.log(reply_content);
        if(reply_content==""){
            showTip("信息不完整",'error');
            return false;
        }
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/Wchat/sendMessage')}",
            data : {"reply_content":reply_content,'type':1
            },
            success : function(data) {
                console.log(data);
                showTip(data["message"],'success');
            }
        });
    }
    //检测会员是否存在
    function testUser(id,text) {
        console.log(text);
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/Wchat/testUser')}",
            data : {'name_user':text},
            success : function(data) {
                console.log(data);
                if(data.code==0){
                    data["message"]='用户不存在';
                    showTip(data["message"],'success');
                }

            }
        });
    }
    //指定会员回复
    function send_onemessage() {
        var user_name = $("#user_name").val();
        var reply_content = $("#reply_one_content").val();
        console.log(user_name+reply_content);
        if(user_name==""||reply_content==""){
            showTip("信息不完整",'error');
            return false;
        }
        // return false;
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/Wchat/sendMessage')}",
            data : {'user_name':user_name,"reply_content":reply_content,'type':2},
            success : function(data) {
                console.log(data);
                showTip(data["message"],'success');


            }
        });
    }
    //分页加载会员
    function LoadingInfo(page) {
        $(".page").remove();
        console.log("pageaaaaa"+page);
        //拿到批量回复id组
        $.each($('input[type=checkbox]:checked.vue_index'), function () {
            app.uid.push($(this).val());
        });
        console.log(app.uid);
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/Wchat/getUsers')}",
            data : {'page':page,"page_size" : $("#showNumber").val()},
            success : function(data) {
                if (data["data"].length > 0) {
                    console.log(data["data"]);
                    //设置CheckBox未选中
                    $('input[type=checkbox]:checked.vue_index').prop("checked",false);
                    app.items = data["data"];
                }
                setTimeout(function () {
                    //设置已选中
                    for(var i=0;i<app.uid.length;i++){
                        console.log(app.uid[i]);
                        $.each($('input[type=checkbox].vue_index'), function () {
                            console.log("sss"+$(this).val());
                            if(app.uid[i]==$(this).val()){
                                console.log("aaaa"+$(this).val());
                                $(this).prop("checked",true);
                            }
                        });

                    }
                },500);
                initPageData(data["page_count"],data['data'].length,data['total_count']);
                $("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));

            }
        });
    }
    //部分会员回复
    function send_area_message() {
        console.log("send_area_message");
        // 拿到回复内容
        var reply_content = $("#reply_area_content").val();
        console.log(reply_content);
        //拿到批量回复id组
        $.each($('input[type=checkbox]:checked.vue_index'), function () {
            app.uid.push($(this).val());
        });
        console.log(app.uid);
        //去除重复元素
        var result = [];
        for(var i=0;i<app.uid.length;i++){
            if(result.indexOf(app.uid[i])==-1){
                result.push(app.uid[i])
            }
        } console.log("ffff");
        console.log(result);
        if(result==""||reply_content==""){
            showTip("信息不完整",'error');
            return false;
        }
        // return false;
        $.ajax({
            type : "post",
            url : "{:__URL('ADMIN_MAIN/Wchat/sendMessage')}",
            data : { 'reply_content' : reply_content,"reply_user_ids" : result.toString(),'type':3 },
            success : function(data) {
                console.log(data);
                showTip(data["message"],'success');
            }
        });
    }
</script>
{/block}